package cn.blnp.net.flowable.api.manager;

import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.*;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * <h3>执行命令案例演示</h3>
 *
 * @author <a href="mailto:blnp.yibin@qq.com">lyb</a>
 * @version 1.0
 * @since 2025/4/30 11:10
 */
@Slf4j
@SpringBootTest
public class CmdApiTest {

    @Resource
    private ManagementService managementService;
    @Resource
    private RepositoryService repositoryService;
    @Resource
    private HistoryService historyService;
    @Resource
    private TaskService taskService;
    @Resource
    private RuntimeService runtimeService;

    /**
     *  常用API方法介绍：
     *
     *  //执行自定义命令，使用的默认的配置
     *  <T> T executeCommand(Command<T> command);
     *
     *  //执行自定义命令，使用自定义配置
     *  <T> T executeCommand(CommandConfig config, Command<T> command);
     **/
    
    /**
     * <p><b>用途:自定义命令演示<b></p>
     * @author <a href="mailto:blnp.yibin@qq.com">lyb</a>
     * @since 11:17 2025/4/30
     * @params [] 
     * @param  
     * @return void
    **/
    @Test
    public void test() {
        //准备参数
        Date curDate = new Date();
        log.info("当前时间为：{}", curDate);
        String express = "${dateFormat.format(date)}";
        Map<String, Object> variableMap = new HashMap<>();
        variableMap.put("date", curDate);
        variableMap.put("dateFormat", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"));

        //调用执行表达式的CMD
        Object result = managementService.executeCommand(
                new ExecuteExpressionCmd(express, variableMap));
        log.info("格式化后：{}", result);

        /**
         *  演示结果：
         *  2025-04-30 11:24:11.447  INFO 75216 --- [           main] c.b.net.flowable.api.manager.CmdApiTest  : 当前时间为：Wed Apr 30 11:24:11 CST 2025
         * 2025-04-30 11:24:11.493  INFO 75216 --- [           main] c.b.net.flowable.api.manager.CmdApiTest  : 格式化后：2025-04-30 11:24:11.447
         **/
    }
}
